package com.lyl.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lyl.domain.Notice;
import com.lyl.mapper.NoticeMapper;
import com.lyl.service.NoticeService;
import org.springframework.util.StringUtils;


/**
 * @author lylbell
 * @date 2021-06-22 13:31
 */
    
@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements NoticeService{


    /**
     * 根据条件分页查询公告
     *
     * @param page
     * @param title     公告的标题
     * @param startTime 公告的创建开始时间
     * @param endTime   公告的创建结束时间时间
     * @param status    公告的状态
     * @return
     */
    @Override
    public Page<Notice> findByPage(Page<Notice> page, String title, String startTime, String endTime, Integer status) {
        return page(page,new LambdaQueryWrapper<Notice>()
                .like(!StringUtils.isEmpty(title),Notice::getTitle,title)
                .between(!StringUtils.isEmpty(startTime)&&!StringUtils.isEmpty(endTime),Notice::getCreated,startTime,endTime + " 23:59:59")
                .eq(status != null,Notice::getStatus,status)
        );
    }
}
